# Maintainer: Rémy Oudompheng <remy@archlinux.org>

pkgname=texlive-langkorean
pkgver=2021.58468
_revnr=${pkgver#2021.}
pkgrel=1
pkgdesc="TeX Live - Fonts and macro packages to typeset Korean texts"
license=('GPL')
arch=(any)
depends=('texlive-core')
groups=('texlive-lang')
url='http://tug.org/texlive/'
source=("https://sources.archlinux.org/other/texlive/$pkgname-$pkgver-src.zip" "$pkgname.maps")
options=('!emptydirs')
sha256sums=('65da5065850e516840ade0522dca2fe0ecbbcabe38c68744372513943c6c61fc'
            'd948fbcd015ca101eb2ccf197f5a835e864a0c9b6be638de8355444ced378a9b')

build() {
   cd "$srcdir"
   for p in *.tar.xz; do
	   bsdtar -xf $p
   done
   rm -rf tlpkg
}

package() {
   install -m755 -d "$pkgdir"/var/lib/texmf/arch/installedpkgs
   sed -i '/^#/d' CONTENTS
   install -m644 CONTENTS "$pkgdir"/var/lib/texmf/arch/installedpkgs/${pkgname}_${_revnr}.pkgs
   install -m644 $pkgname.maps "$pkgdir"/var/lib/texmf/arch/installedpkgs/
   install -m755 -d "$pkgdir"/usr/share
   wanteddirs=$(for d in *; do test -d $d && [[ $d != texmf* ]] && echo $d; done) || true
   for dir in $wanteddirs; do
     find $dir -type d -exec install -d -m755 "$pkgdir"/usr/share/texmf-dist/'{}' \;
     find $dir -type f -exec install -m644 '{}' "$pkgdir"/usr/share/texmf-dist/'{}' \;
   done
   if [[ -d texmf-dist ]]; then
     find texmf-dist -type d -exec install -d -m755 "$pkgdir"/usr/share/'{}' \;
     find texmf-dist -type f -exec install -m644 '{}' "$pkgdir"/usr/share/'{}' \;
   fi
   if [[ -d "$pkgdir"/usr/share/texmf-dist/scripts ]]; then
     find "$pkgdir"/usr/share/texmf-dist/scripts -type f -exec chmod a+x '{}' \;
   fi

    # scripts links
    _linked_scripts="
kotex-utils/jamo-normalize.pl
kotex-utils/komkindex.pl
kotex-utils/ttf2kotexfont.pl
"
    install -m755 -d "$pkgdir"/usr/bin
    for _script in ${_linked_scripts}; do
        _scriptbase=$(basename $_script)
        _scriptbase=${_scriptbase%.*}
        ln -s /usr/share/texmf-dist/scripts/${_script} "${pkgdir}/usr/bin/${_scriptbase}"
    done
}
